package com.smarthealthcare.service.impl;

import java.util.Collections;
import java.util.List;

import com.smarthealthcare.domain.Department;
import com.smarthealthcare.domain.Doctor;
import com.smarthealthcare.mapper.DepartmentMapper;
import com.smarthealthcare.mapper.DoctorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.smarthealthcare.mapper.RegisterMapper;
import com.smarthealthcare.domain.Register;
import com.smarthealthcare.service.IRegisterService;

/**
 * 预约Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-11-23
 */
@Service
public class RegisterServiceImpl implements IRegisterService 
{
    @Autowired
    private RegisterMapper registerMapper;

    @Autowired
    private DepartmentMapper departmentMapper;
    @Autowired
    private DoctorMapper doctorMapper;
    /**
     * 查询预约
     * 
     * @param id 预约主键
     * @return 预约
     */
    @Override
    public Register selectRegisterById(Long id)
    {
        return registerMapper.selectRegisterById(id);
    }

    /**
     * 查询预约列表
     * 
     * @param register 预约
     * @return 预约
     */
    @Override
    public List<Register> selectRegisterList(Register register)
    {
        List<Register> list = registerMapper.selectRegisterList(register);
        for (Register r : list) {
            Long departmentId = r.getDepartmentId();
            Department department = departmentMapper.selectDepartmentById(departmentId);
            r.setDepartment(department);
            Long doctorId = r.getDoctorId();
            Doctor doctor = doctorMapper.selectDoctorById(doctorId);
            r.setDoctor(doctor);
        }
        return list;
    }

    @Override
    public List<Register> selectAll() {
        List<Register> list = registerMapper.getAll();
        for (Register r : list) {
            Long departmentId = r.getDepartmentId();
            Department department = departmentMapper.selectDepartmentById(departmentId);
            r.setDepartment(department);
            Long doctorId = r.getDoctorId();
            Doctor doctor = doctorMapper.selectDoctorById(doctorId);
            r.setDoctor(doctor);
        }
        return list;
    }

    /**
     * 新增预约
     * 
     * @param register 预约
     * @return 结果
     */
    @Override
    public int insertRegister(Register register)
    {
        return registerMapper.insertRegister(register);
    }

    /**
     * 修改预约
     * 
     * @param register 预约
     * @return 结果
     */
    @Override
    public int updateRegister(Register register)
    {
        return registerMapper.updateRegister(register);
    }

    /**
     * 批量删除预约
     * 
     * @param ids 需要删除的预约主键
     * @return 结果
     */
    @Override
    public int deleteRegisterByIds(Long[] ids)
    {
        return registerMapper.deleteRegisterByIds(ids);
    }

    /**
     * 删除预约信息
     * 
     * @param id 预约主键
     * @return 结果
     */
    @Override
    public int deleteRegisterById(Long id)
    {
        return registerMapper.deleteRegisterById(id);
    }

}
